﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace ImportPiket
{
    /// <summary>
    /// Логика взаимодействия для ImportPage2.xaml
    /// </summary>
    public partial class ImportPage2 : Page
    {
        /// <summary>
        /// Флаг - инициализация формы
        /// </summary>
        bool isInit;

        public ImportPage2()
        {
            isInit = false;
            this.InitializeComponent();
            isInit = true;
            if (PrjProperty.txtData == "")
            {
                try
                {
                    // Create new StreamReader
                    StreamReader sr = new StreamReader(PrjProperty.fileName, Encoding.Default);
                    // Get all text from the file
                    string str = sr.ReadToEnd();
                    // Close the StreamReader
                    sr.Close();
                    // Show the text in the rich textbox rtbMain
                    textBoxData.Text = str;
                }
                catch (Exception errorMsg)
                {
                    textBoxData.Text = errorMsg.Message;
                }
            }
            else
                textBoxData.Text = PrjProperty.txtData;
        }
        /// <summary>
        /// Событие текст изменен
        /// </summary>
        private void TextBox_TextChanged_1(object sender, TextChangedEventArgs e)
        {
            if (isInit)
                PrjProperty.txtData = textBoxData.Text;
        }
    }
}
